package top.lingchen.spring5.aopanno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Author 凌宸
 * @create 2021-11-29 下午 11:44
 * @Description 增强的类
 * @Version 1.0
 */
@Component
@Aspect
@Order(3)
public class UserProxy {
    // 相同切入点抽取
    @Pointcut(value = "execution(* top.lingchen.spring5.aopanno.User.add(..))")
    public void pointDemo(){

    }

    // 前置通知
    @Before(value = "pointDemo()")
    public void before(){
        System.out.println("before.....");
    }
    // 最终通知
    @After(value = "execution(* top.lingchen.spring5.aopanno.User.add(..))")
    public void after(){
        System.out.println("after......");
    }
    // 后置通知 （返回通知）
    @AfterReturning(value = "execution(* top.lingchen.spring5.aopanno.User.add(..))")
    public void afterReturning(){
        System.out.println("afterReturning......");
    }
    // 异常通知
    @AfterThrowing(value = "execution(* top.lingchen.spring5.aopanno.User.add(..))")
    public void afterThrowing(){
        System.out.println("afterThrowing......");
    }
    // 环绕通知
    @Around(value = "execution(* top.lingchen.spring5.aopanno.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
        System.out.println("环绕之前......");
        // 被增强的方法执行
        proceedingJoinPoint.proceed();
        System.out.println("环绕之后......");
    }
}
